<?php

namespace App\Repos;

use App\Models\ShopVisitor;

class ShopVisitorRepo 
{
    public static function countByDate($where)
    {
    	$today = date('Y-m-d');
    	$day_1 = date('Y-m-d',strtotime("-1 week"));
    	$day_2 = date('Y-m-d',strtotime("-5 day"));
    	$day_3 = date('Y-m-d',strtotime("-4 day"));
    	$day_4 = date('Y-m-d',strtotime("-3 day"));
    	$day_5 = date('Y-m-d',strtotime("-2 day"));
    	
    	$day_6 = date('Y-m-d',strtotime("yesterday"));
    	$data['today'] = ShopVisitor::where($where)
    						->groupBy('user_id')
    						->whereDate('created_at',$today)
    						->count();
    	
    	
    	
    	
    	
    	$data['day_6'] = ShopVisitor::where($where)
    						->groupBy('user_id')
    						->whereDate('created_at',$day_6)
    						->count();
    	$data['day_5'] = ShopVisitor::where($where)
    						->groupBy('user_id')
    						->whereDate('created_at',$day_5)
    						->count();	
    	$data['day_4'] = ShopVisitor::where($where)
    						->groupBy('user_id')
    						->whereDate('created_at',$day_4)
    						->count();	
    	$data['day_3'] = ShopVisitor::where($where)
    						->groupBy('user_id')
    						->whereDate('created_at',$day_3)
    						->count();	
    	$data['day_2'] = ShopVisitor::where($where)
    						->groupBy('user_id')
    						->whereDate('created_at',$day_2)
    						->count();	
    	$data['day_1'] = ShopVisitor::where($where)
    						->groupBy('user_id')
    						->whereDate('created_at',$day_1)
    						->count();																						
    	return $data;																																		

    }

    public static function create($data)
    {
        return ShopVisitor::firstOrCreate($data);
    }
}
